import request from '@/utils/request'

export function getCateList (params) {
  return request(
    {
      url: '/categories',
      method: 'GET',
      params
    }
  )
}

export function getParentCateList () {
  return request(
    {
      url: '/categories',
      method: 'GET',
      params: {
        type: 2
      }
    }
  )
}

export function addCate (data) {
  return request(
    {
      url: '/categories',
      method: 'POST',
      data
    }
  )
}

export function getCatePramas () {
  return request(
    {
      url: '/categories',
      method: 'GET'
    }
  )
}

export function handleChange (id, params) {
  console.log(123)
  return request(
    {
      url: `/categories/${id}/attributes`,
      method: 'GET',
      params

    }
  )
}

export function addParams (id, name, sel) {
  return request(
    {
      url: `/categories/${id}/attributes`,
      method: 'POST',
      data: {
        attr_name: name,
        attr_sel: sel
      }
    }
  )
}

export function showEditDialog (id, attrId, sel) {
  console.log(attrId)
  return request(
    {
      url: `categories/${id}/attributes/${attrId}`,
      method: 'GET',
      params: {
        attr_sel: sel
      }
    }
  )
}

export function editParams (data) {
  return request(
    {
      url: `categories/${data.cat_id}/attributes/${data.attr_id}`,
      method: 'PUT',
      data: {
        attr_name: data.attr_name,
        attr_sel: data.attr_sel,
        attr_vals: data.attr_vals
      }
    }
  )
}

export function removeParams (data) {
  return request(
    {
      url: `categories/${data.cat_id}/attributes/${data.attr_id}`,
      method: 'DELETE'
    }
  )
}

export function handleInputConfirm (data) {
  return request(
    {
      url: `categories/${data.cat_id}/attributes/${data.attr_id}`,
      method: 'PUT',
      data: {
        attr_name: data.attr_name,
        attr_sel: data.attr_sel,
        attr_vals: data.attr_vals.join(' ')
      }
    }
  )
}
